package com.xyht.medicine_management_system.modules.medicineSource.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.annotation.RequestPass;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.medicineSource.entity.req.MmsMedicineSourceReq;
import com.xyht.medicine_management_system.modules.medicineSource.service.MmsMedicineSourceService;
import com.xyht.medicine_management_system.modules.user.entity.req.MmsUserExamineApplyReq;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 药知源 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-11-26
 */
@RestController
@SecretBody
@RequestMapping("/medicineSource")
public class MmsMedicineSourceController {
    @Resource
    private MmsMedicineSourceService mmsMedicineSourceService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @PostMapping("/add")
    @ApiModelProperty(value = "药知源添加")
    public ResponseResult addMedicineSource(@RequestBody MmsMedicineSourceReq sourceReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsMedicineSourceService.addMedicineSource(sourceReq, user_id);
    }

    @GetMapping("/detail")
    @ApiModelProperty(value = "药知源详情")
    @RequestPass
    public ResponseResult getMedicineSourceDetail(@RequestParam String sourceId,HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdOrNullByRequest(request);
        return mmsMedicineSourceService.getMedicineSourceDetail(sourceId,userId);
    }

    @GetMapping("/list")
    @RequestPass
    @ApiModelProperty(value = "药知源列表")
    public ResponseResult getMedicineSourceList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam("searchStr") String searchStr) {
        return mmsMedicineSourceService.getMedicineSourceList(pageNum, pageSize, searchStr);
    }

    @PostMapping("/update")
    @ApiModelProperty(value = "药知源修改")
    public ResponseResult updateMedicineSource(@RequestBody MmsMedicineSourceReq sourceReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsMedicineSourceService.updateMedicineSource(sourceReq, user_id);
    }

    @PostMapping("/delete")
    @ApiModelProperty(value = "药知源删除")
    public ResponseResult deleteMedicineSource(@RequestBody MmsMedicineSourceReq sourceReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsMedicineSourceService.deleteMedicineSource(sourceReq, user_id);
    }

    @GetMapping("/display")
    @RequestPass
    @ApiModelProperty(value = "药知源展示列表")
    public ResponseResult appDisplayMedicineSource(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return mmsMedicineSourceService.appDisplayMedicineSource(pageNum,pageSize);
    }
}

